textview: Don't leave embedded children behind
authorMatthias Clasen <mclasen@redhat.com>
Fri, 5 Nov 2021 22:54:06 +0000 (18:54 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 8 Nov 2021 19:17:42 +0000 (14:17 -0500)
When scrolling embedded widgets out of view,
they sometimes get left behind because we don't
reallocated them. To avoid that, move _all_ children
out of view in size_allocate, and let the current
child allocation plumbing move the visible ones
back in place.

gtk/gtktextview.c

index 340d12b2d9c23ae9bb5fb5d072388659c41b2a29..db23e9ad868d9ee79322e1de9484bf1fe028e8e8 100644 (file)
@@ -4409,6 +4409,8 @@ gtk_text_view_allocate_children (GtkTextView *text_view)
     {
       const AnchoredChild *child = iter->data;
       GtkTextIter child_loc;
+      GtkRequisition child_req;
+      GtkAllocation allocation;
 
       /* We need to force-validate the regions containing children. */
       gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
@@ -4429,6 +4431,15 @@ gtk_text_view_allocate_children (GtkTextView *text_view)
         }
 
       gtk_text_layout_validate_yrange (priv->layout, &child_loc, 0, 1);
+
+      gtk_widget_get_preferred_size (child->widget, &child_req, NULL);
+
+      allocation.x = - child_req.width;
+      allocation.y = - child_req.height;
+      allocation.width = child_req.width;
+      allocation.height = child_req.height;
+
+      gtk_widget_size_allocate (child->widget, &allocation, -1);
     }
 }